home *** CD-ROM | disk | FTP | other *** search
- /*
- * WESelectors.c
- *
- * WASTE PROJECT
- * Routines for manipulating selector lookup tables
- *
- * Copyright (c) 1993-1995 Marco Piovanelli
- * All Rights Reserved
- *
- * C port by Dan Crevier
- *
- */
-
-
- #include "WASTEIntf.h"
-
- // MPW can't handle FIELD_DESC stuff (duh!)
-
- #ifdef applec
-
- // this is **ugly** and will break if we change the declaration of WERec
-
- static WELookupTable _weMainSelectorTable[] = {
- { 'clik',0x68,0x4 },
- { 'drag',0x98,0x4 },
- { 'line',0x08,0x4 },
- { 'port',0x00,0x4 },
- { 'post',0x94,0x4 },
- { 'pre ',0x90,0x4 },
- { 'refc',0x80,0x4 },
- { 'runa',0x10,0x4 },
- { 'scrl',0x78,0x4 },
- { 'styl',0x0C,0x4 },
- { 'text',0x04,0x4 },
- { 'tsmd',0x84,0x4 },
- { 'xdrg',0xA0,0x4 },
- { 'c2p ',0xB4,0x4 },
- { 'cbyt',0xC0,0x4 },
- { 'ctyp',0xC4,0x4 },
- { 'draw',0xAC,0x4 },
- { 'lbrk',0xB8,0x4 },
- { 'wbrk',0xBC,0x4 },
- { 0, 0x00,0x0 }};
-
- #if WASTE_OBJECTS
-
- static WELookupTable _weObjectHandlerSelectorTable[] = {
- { 'clik',0x10,0x4 },
- { 'draw',0x0C,0x4 },
- { 'free',0x08,0x4 },
- { 'new ',0x04,0x4 },
- { 'strm',0x14,0x4 },
- { 0, 0x0,0x0 }};
-
- #endif // WASTE_OBJECTS
-
- #else
-
- // proper way of defining selector tables
-
- #define FIELD_OFFSET(FIELD, STRUCT) (short) &((STRUCT *) 0L)->FIELD
- #define FIELD_SIZE(FIELD, STRUCT) (short) sizeof(((STRUCT *) 0L)->FIELD)
- #define FIELD_DESC(FIELD, STRUCT) { FIELD_OFFSET(FIELD, STRUCT), FIELD_SIZE(FIELD, STRUCT) }
-
- static WELookupTable _weMainSelectorTable[] = {
- { weRefCon, FIELD_DESC(refCon, WERec) },
- { wePort, FIELD_DESC(port, WERec) },
- { weText, FIELD_DESC(hText, WERec) },
- { weCharToPixelHook, FIELD_DESC(charToPixelHook, WERec) },
- { weCharByteHook, FIELD_DESC(charByteHook, WERec) },
- { weCharTypeHook, FIELD_DESC(charTypeHook, WERec) },
- { weClickLoop, FIELD_DESC(clickLoop, WERec) },
- { weCurrentDrag, FIELD_DESC(currentDrag, WERec) },
- { weDrawTextHook, FIELD_DESC(drawTextHook, WERec) },
- { weLineBreakHook, FIELD_DESC(lineBreakHook, WERec) },
- { weLineArray, FIELD_DESC(hLines, WERec) },
- { wePixelToCharHook, FIELD_DESC(pixelToCharHook, WERec) },
- { weTSMPostUpdate, FIELD_DESC(tsmPostUpdate, WERec) },
- { weTSMPreUpdate, FIELD_DESC(tsmPreUpdate, WERec) },
- { weRunArray, FIELD_DESC(hRuns, WERec) },
- { weScrollProc, FIELD_DESC(scrollProc, WERec) },
- { weStyleTable, FIELD_DESC(hStyles, WERec) },
- { weTSMDocumentID, FIELD_DESC(tsmReference, WERec) },
- { weWordBreakHook, FIELD_DESC(wordBreakHook, WERec) },
- { weTranslateDragHook, FIELD_DESC(translateDragHook, WERec) },
- { 0, 0, 0 }};
-
- #if WASTE_OBJECTS
-
- static WELookupTable _weObjectHandlerSelectorTable[] = {
- { weClickHandler, FIELD_DESC(clickHandler, WEOHTableElement) },
- { weDrawHandler, FIELD_DESC(drawHandler, WEOHTableElement) },
- { weDisposeHandler, FIELD_DESC(freeHandler, WEOHTableElement) },
- { weNewHandler, FIELD_DESC(newHandler, WEOHTableElement) },
- { weStreamHandler, FIELD_DESC(streamHandler, WEOHTableElement) },
- { 0, 0, 0 }};
-
- #endif // WASTE_OBJECTS
-
- #endif // !applec
-
- pascal void _WELookupSelector(const WELookupTable *table, WESelector selector, WEFieldDescriptor *desc)
- {
- for ( ; table->selector != selector ; table++ )
- if ( * (long *) &(table->desc) == 0L )
- break;
-
- *desc = table->desc;
- }
-
- pascal OSErr _WEGetField(const WELookupTable *table, WESelector selector, long *info, void *structure)
- {
- WEFieldDescriptor desc;
-
- _WELookupSelector(table, selector, &desc);
-
- if (desc.fLength == 0)
- return weUndefinedSelectorErr;
-
- *info = * (long *) ((long) structure + desc.fOffset);
- return noErr;
- }
-
- pascal OSErr _WESetField(const WELookupTable *table, WESelector selector, long *info, void *structure)
- {
- WEFieldDescriptor desc;
-
- _WELookupSelector(table, selector, &desc);
-
- if (desc.fLength == 0)
- return weUndefinedSelectorErr;
-
- * (long *) ((long) structure + desc.fOffset) = *info;
- return noErr;
- }
-
- pascal OSErr WEGetInfo(WESelector selector, void *info, WEHandle hWE)
- {
- return _WEGetField(_weMainSelectorTable, selector, (long *)info, (void *)*hWE);
- } // WEGetInfo
-
- pascal OSErr WESetInfo(WESelector selector, const void *info, WEHandle hWE)
- {
- OSErr err;
-
- err = _WESetField(_weMainSelectorTable, selector, (long *)info, (void *)*hWE);
-
- // the hook fields can never be NULL, so replace any NULL field with the default address
- _WESetStandardHooks(hWE);
-
- return err;
- } // WESetInfo
-
- #if WASTE_OBJECTS
- // for some reason _WESetField doesn't work from other files (?)
- pascal OSErr _WESetHandler(WESelector selector, long *info, void *structure)
- {
- return _WESetField(_weObjectHandlerSelectorTable, selector, info, structure);
- }
- #endif